﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        //设置两个同向指针
        size_t left = 0, right = 0;
        int ret = 0;
        //数组保存计数
        int arr[128];
        //进窗口
        for (right = 0; right < s.size(); right++)
        {
            arr[s[right]]++;
            //出窗口
            //遇到重复让arr[s[i]]变为1
                //更新
               
                //跳到重复的下一个字符
            while (arr[s[right]] > 1)
            {
                arr[s[left]]--;
                left++;
            }
            //更新 
                ret = max(ret, (int)(right - left+1));
            
        }
        return ret;
    }
};


class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        //设置两个同向指针
        size_t left = 0, right = 0;
        int ret = 0;
        //数组保存计数
        int arr[128];
        //进窗口
        while (right < s.size())
        {
            arr[s[right]]++; // 进⼊窗⼝
            while (arr[s[right]] > 1) // 判断
                arr[s[left++]]--; // 出窗⼝
            ret = max(ret, (int)(right - left + 1));// 更新结果
            right++; // 让下⼀个元素进⼊窗⼝
        }
        return ret;
    }
};